﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.dataAcess;
using dhDataAcess.baseBLL;

namespace dhSystemBLL.basicData
{
  public  class companyinfoBLL
    {
        private companyinfoTableAdapter  _companyAdapter = null;
        private companyinfoTableAdapter  companyAdapter
        {
            get
            {
                if (_companyAdapter == null) _companyAdapter = new companyinfoTableAdapter();
                return _companyAdapter;
            }
        }
        /// <summary>
        /// 查询公司信息表
        /// </summary>
        /// <returns></returns>

        public sysDataSet.companyinfoDataTable getcompanyinfoAll()
        {
            try
            {
                return companyAdapter.GetDatacompanyinfoAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 根据公司名查询公司信息表
        /// </summary>
        /// <param name="cname"></param>
        /// <returns></returns>

        public sysDataSet.companyinfoDataTable getcompanyinfoAll(string cname)
        {
            try
            {

                return companyAdapter .GetDatacompanyByname(cname);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }


       

        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        public int companyinfoInsert(companyinfoModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                companyinfoDAL company = new companyinfoDAL(tn, conn);
                company.companyinfoInsert(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        public int companyinfoUpdate(companyinfoModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                companyinfoDAL company = new companyinfoDAL(tn, conn);
                company.companyinfoUpdate(row );
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="cname"></param>
        /// <returns></returns>

        public int companyinfoDel(string cname)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                companyinfoDAL company = new companyinfoDAL(tn, conn);
                company.companyinfoDel(cname);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 根据电话返回一个公司名称
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>

        public int companyinfoRetName(string mobile)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                companyinfoDAL company = new companyinfoDAL(tn, conn);
                company.companyinforetcname( mobile);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
